﻿
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Entity;
using DataControls;

namespace GiaoVien_QuanLy_DeTai
{
    public partial class LOAIDETAI_Form : Form
    {
        LOAIDETAI loaidetai = new LOAIDETAI();
        LOAIDETAI_Data loaidetai_Data = new LOAIDETAI_Data();
        public LOAIDETAI_Form()
        {
            InitializeComponent();
        }

        private void LOAIDETAI_Form_Load(object sender, EventArgs e)
        {
            txtLoaiDeTai.Text = "";
            txtSoTC.Text = "";
        }

        private void btnHienThi_Click(object sender, EventArgs e)
        {
            loaidetai.hienthi_LoaiDeTai(dtgLDT);
        }

        private void btnThem_Click(object sender, EventArgs e)
        {
            if (txtLoaiDeTai.Text == "")
            {
                txtLoaiDeTai.Focus();
                MessageBox.Show("Ban chua dien Loai De Tai");
                return;
            }
            else if (txtSoTC.Text == "")
            {
                txtSoTC.Focus();
                MessageBox.Show("Ban chua dien so tin chi");
                return;
            }
            else if (loaidetai_Data.kiemtra_LoaiDeTai(txtLoaiDeTai.Text.ToString()))
            {
                txtLoaiDeTai.Focus();
                MessageBox.Show("ban nhap trung loai de tai");
                return;
            }

            else
            {
                loaidetai.loaiDT = txtLoaiDeTai.Text.ToString();
                try
                {
                    if ((loaidetai.soTC = Convert.ToInt16(txtSoTC.Text)) <= 0)
                    {
                        MessageBox.Show("Ban chua nhap dung so tin chi");
                        txtSoTC.Focus();
                        return;
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Kieu Du Lieu Khong Dung \n" + ex.Message);
                }
                loaidetai.them_LoaiDeTai(loaidetai);
                loaidetai.hienthi_LoaiDeTai(dtgLDT);

                txtLoaiDeTai.Text = "";
                txtSoTC.Text = "";
            }
        }

        private void btnXoa_Click(object sender, EventArgs e)
        {
            if (txtLoaiDeTai.Text == "")
            {
                txtLoaiDeTai.Focus();
                MessageBox.Show("Ban chua dien Loai De Tai");
                return;
            }
            else if (loaidetai_Data.kiemtraLoaiDT_DeTai(txtLoaiDeTai.Text.ToString()))
            {
                MessageBox.Show("Ban chua xoa Loai De Tai trong De Taii");
                return;
            }
            else
            {
                loaidetai.xoa_LoaiDeTai(txtLoaiDeTai.Text.ToString());
                loaidetai.hienthi_LoaiDeTai(dtgLDT);

                txtLoaiDeTai.Text = "";
                txtSoTC.Text = "";
            }
        }

        private void btnSua_Click(object sender, EventArgs e)
        {
            if (txtLoaiDeTai.Text == "")
            {
                txtLoaiDeTai.Focus();
                MessageBox.Show("Ban chua dien Loai De Tai");
                return;
            }
            else if (txtSoTC.Text == "")
            {
                txtSoTC.Focus();
                MessageBox.Show("Ban chua dien so tin chi");
                return;
            }

            else
            {
                loaidetai.loaiDT = txtLoaiDeTai.Text.ToString();
                try
                {
                    if ((loaidetai.soTC = Convert.ToInt16(txtSoTC.Text)) <= 0)
                    {
                        MessageBox.Show("Ban chua nhap dung so tin chi");
                        txtSoTC.Focus();
                        return;
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Kieu Du Lieu Khong Dung \n" + ex.Message);
                }
                loaidetai.sua_LoaiDeTai(loaidetai);
                loaidetai.hienthi_LoaiDeTai(dtgLDT);

                txtLoaiDeTai.Text = "";
                txtSoTC.Text = "";
            }
        }

        private void dtgLDT_RowEnter(object sender, DataGridViewCellEventArgs e)
        {
            dtgLDT.AllowUserToAddRows = false;
            int dong = e.RowIndex;
            txtLoaiDeTai.Text = dtgLDT.Rows[dong].Cells[0].Value.ToString();
            txtSoTC.Text = dtgLDT.Rows[dong].Cells[1].Value.ToString();
        }

        private void txtLoaiDeTai_MouseClick(object sender, MouseEventArgs e)
        {
            txtLoaiDeTai.Text = "";
            txtSoTC.Text = "";
        }





    }
}
